<template>
  <ve-modal :showCancel="modalInfo.showCancel" title="提示" :okText="modalInfo.okText" v-model="visible" @confirm="modalInfo.onOk">
    <view class="modal-content" v-html="modalInfo.content" />
  </ve-modal>
</template>
<script setup>
  import { ref, reactive } from 'vue'
  import { orderIsTiexing } from '../../../tools'

  // 弹窗配置初始化
  const modalInfo = reactive({
    content: '',
    okText: '去匹配',
    showCancel: false,
    cancelText: '关闭',
    onOk: () => {
      visible.value = false
    },
  })
  const visible = ref(false)
  const open = (record, operateStr = '', callback = () => {}) => {
    if (!orderIsTiexing(record)) return false
    switch (operateStr) {
      // 已完成、已还车不调用铁行接口
      case 'notCallTiexing':
        visible.value = true
        Object.assign(modalInfo, {
          content: '无法变更铁行平台已还车和已完成的订单的车辆。请确认是否只在企橙修改车牌号？',
          onOk: [modalInfo.onOk, callback],
          okText: '确认',
          showCancel: true,
        })
        break
      // 还车确认
      case 'returnCarSubmit':
      // 换车确认
      case 'changeCarSubmit':
      // 交车确认
      case 'giveCarSubmit':
      // 订单改排
      case 'editShortOrderReschedule':
      // 修改车牌号
      case 'editShortOrderLicenseNo':
      // 修改订单
      case 'editShortOrder':
        visible.value = true
        Object.assign(modalInfo, {
          content: `<view>
              订单<text style="color: #3491fa">${record.channelOrderCode}</text>在铁行平台<text style="color: #f76964ff">${getErrorStrFn(
            operateStr,
          )}</text>请前往铁行平台查看
              <text style="color: #3491fa">${record.carLicenseNo}</text>的车辆情况。
            </view>`,
          okText: '我已知晓',
          onOk: [modalInfo.onOk, callback],
        })
        break
      // 交车
      case 'givecar':
        visible.value = !record.carModelName && record.orderStatus == 100
        Object.assign(modalInfo, {
          content: `请先前往<b>PC端后台-业务>渠道管理>OTA渠道管理模块</b>，完成当前渠道订单车辆的匹配，再进行交车操作`,
          okText: '我已知晓',
          onOk: modalInfo.onOk,
        })

        break
      // 还车
      case 'returnCar':
        visible.value = !record.carModelName && record.orderStatus == 200
        Object.assign(modalInfo, {
          content: `请先前往<b>PC端后台-业务>渠道管理>OTA渠道管理模块</b>，完成当前渠道订单车辆的匹配，再进行还车操作`,
          okText: '我已知晓',
          onOk: modalInfo.onOk,
        })
        break
      // 订单换车
      case 'changecar':
        visible.value = !record.carModelName && record.orderStatus == 200
        Object.assign(modalInfo, {
          content: `请先前往<b>PC端后台-业务>渠道管理>OTA渠道管理模块</b>，完成当前渠道订单车辆的匹配，再进行换车操作`,
          okText: '我已知晓',
          onOk: modalInfo.onOk,
        })
        break
    }
    return visible.value
  }

  const getErrorStrFn = (val) => {
    switch (val) {
      case 'giveCarSubmit':
        return '交车失败！'
      case 'returnCarSubmit':
        return '还车失败！'
      default:
        return '更换车辆失败！'
    }
  }
  defineExpose({
    open,
  })
</script>
<style>
  .modal-content {
    padding-bottom: 20rpx;
  }
</style>
